package com.hllxd.hism.star.basic.service.service;

import com.alibaba.fastjson.JSON;
import com.hllxd.hism.star.basic.service.dao.mapper.mis.KpiReportMapper;
import com.hllxd.hism.star.basic.service.model.metric.KpiReportEntity;
import com.hllxd.hism.star.basic.service.model.metric.KpiReportResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiyong.lxy
 * @date 2020-10-12 16:51
 */
@Slf4j
@Service("kpiReportService")
public class KpiReportServiceImpl implements KpiReportService {

    @Autowired
    private KpiReportMapper metricKpiMapper;




    @Override
    public List<KpiReportEntity> listKanbanReport(String dt, String groupId, String kpiId,String metricId,String ownerId) {
        return metricKpiMapper.listKanbanReport(dt, groupId, kpiId, metricId, ownerId);
    }

    @Override
    public KpiReportResult listReportDetail(String metricId) {
        KpiReportResult result = new KpiReportResult();
        result.meta = metricKpiMapper.listKpiDetail(metricId);
        result.data = metricKpiMapper.listReport(metricId);
        return result;
    }

    @Override public KpiReportEntity getReport(Long id) {
        return metricKpiMapper.getReport(id);
    }

    @Override
    public Long setReport(KpiReportEntity entity) {
        log.info("set param: {}", JSON.toJSONString(entity));
        if(entity.id==null || entity.id==0) {
            log.info("will insert entity.");
            return metricKpiMapper.insertReport(entity);
        } else {
            log.info("will update entity.");
            return metricKpiMapper.updateReport(entity);
        }
    }

    @Override
    public Boolean deleteReport(String ids) {
        return metricKpiMapper.deleteReport(ids);
    }



}
